﻿var mySwiper = new Swiper('.swiper-container',{
    loop: true,
    autoplay: 3000
});






var price = 80; //票价
$(document).ready(function() {
    var $cart = $('#selected-seats'), //座位区
        $counter = $('#counter'), //票数
        $total = $('#total'); //总计金额

    var sc = $('#seat-map').seatCharts({
        map: [  //座位图
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            '__________',
            'aaaaaaaa__',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aa__aa__aa'
        ],
        naming : {
            top : false,
            getLabel : function (character, row, column) {
                return column;
            }
        },
        legend : { //定义图例
            node : $('#legend'),
            items : [
                [ 'a', 'available',   '可选座' ],
                [ 'a', 'unavailable', '已售出']
            ]
        },
        click: function () { //点击事件
            if (this.status() == 'available') { //可选座
                $('<li>'+(this.settings.row+1)+'排'+this.settings.label+'座</li>')
                    .attr('id', 'cart-item-'+this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart);

                $counter.text(sc.find('selected').length+1);
                $total.text(recalculateTotal(sc)+price);

                return 'selected';
            } else if (this.status() == 'selected') { //已选中
                //更新数量
                $counter.text(sc.find('selected').length-1);
                //更新总计
                $total.text(recalculateTotal(sc)-price);

                //删除已预订座位
                $('#cart-item-'+this.settings.id).remove();
                //可选座
                return 'available';
            } else if (this.status() == 'unavailable') { //已售出
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    //已售出的座位
    sc.get(['1_2', '4_4','4_5','6_6','6_7','8_5','8_6','8_7','8_8', '10_1', '10_2']).status('unavailable');

});
//计算总金额
function recalculateTotal(sc) {
    var total = 0;
    sc.find('selected').each(function () {
        total += price;
    });
    return total;
}

$("#riqi1").css({'color':'#0033cc'});
$("#riqi2").on("tap",function(){
    $(this).css( {'border-bottom': '1px solid #0033cc','color': '#0033cc'});
    $("#riqi1").css({'border':'0','color':'black'})
});
$("#riqi1").on("tap",function(){
    $(this).css( {'border-bottom': '1px solid #0033cc','color': '#0033cc'});
    $("#riqi2").css({'border':'0','color':'black'})
});




//ajax的封装
var http;
function getAjax(menthod,action,async,parameter,callback){
    if(window.XMLHttpRequest){
        http=new XMLHttpRequest();
    }else{
        http=new ActiveXObject("Microsoft.XmlHttp");
    }
    http.onreadystatechange= callback;
    if(menthod=="post"){
        http.open(menthod,action,async);
        http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        http.send("li="+parameter);
        console.log("li="+parameter);
        console.log("ajax请求");
    }else{
        http.send(menthod+"=?");
        console.log("ajax请求");
    }
}
function qie1(){
    var user = document.getElementById("jiangsanmeiren").innerHTML;
    var user1 = document.getElementById("riqi1").innerHTML;
    var user2 = document.getElementById("movietime1").innerHTML;
    var user3 = document.getElementById("movieting").innerHTML;
    console.log(user);
    console.log(user1);
    var a=[user,user1,user2,user3];
    console.log(a);
    var c = "../wenzi.do";
    var b = "post";
    getAjax(b,c,true,a,function(){
        tiquname()
    });
}
function tiquname(){
    if(http.readyState==4 && http.status==200) {
        console.log("1回调函数");
        console.log(http.responseText);
        var data = JSON.parse(http.responseText);
        console.log(data);
        var tiname = document.getElementById("tiname");
        var titime = document.getElementById("titime");
        console.log(data[0].dingdan_movie);
        tiname.innerHTML="";
        tiname.innerHTML=data[0].dingdan_movie;

        console.log(data[0].dingdan_riqi);
        console.log(data[0].dingdan_time);
        titime.innerHTML="";
        titime.innerHTML=data[0].dingdan_riqi+data[0].dingdan_time;
    }
}



//
//(function(){
//    var $=(function(){
//        function creatXhr(){
//            var xhr;
//            if(window.XMLHttpRequest){
//                xhr=new XMLHttpRequest();
//            }else{
//                xhr=new ActiveXObject("Microsoft.XmlHttp")
//            }
//            return xhr
//        }
//        return{ajax:function(obj){
//            var xhr=creatXhr();
//            if(obj.async==undefined){
//                obj.async=true;
//            };
//            if(obj.method=="get"){
//                obj.param=null;
//                obj.url=obj.url+"?"+obj.param
//            }
//            xhr.open(obj.method,obj.url,obj.async);
//            if(obj.method=="post"){
//                xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//            };
//            xhr.onreadystatechange=function(){
//                if(xhr.readyState==4 && xhr.status==200) {
//                    obj.success(xhr.responseText)
//                }
//            };
//            xhr.send(obj.param);
//            console.log((obj.param))
//        }
//        }
//    })();
//    window.$=$;
//    window.jq=$;
//})();
// lujingyang.ajax({
//    method:"post",
//    url:"/name.do",
//    param:"name="+name,
//    anync:true,
//    success:tiquname()
//});